﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;
using WebUI.Controls;

namespace WebUI
{
    public partial class PurchaseOrder : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            purchaseLookup.OnAddIMEI = purchaseLookup_OnAddIMEI;
            purchaseLookup.OnAddProduct = purchaseLookup_OnAddProduct;
        }

        public void purchaseLookup_OnAddIMEI(object sender, ListItemEventArgs e)
        {
            try
            {
                string[] imeis = (string[]) e.Data["IMEI"];
                int productID = (int)e.Data["ProductID"];
                purchaseOrder.AddIMEIs(imeis, productID);
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("Sales.aspx.cs", "saleLookup_OnAddIMEI", ex.StackTrace);
                ShowErrorMessage(purchaseOrder, "(*) Error in add IMEI: " + ex.Message);
            }
        }

        public void purchaseLookup_OnAddProduct(object sender, ListItemEventArgs e)
        {
            try
            {
                int productID = (int)e.Data["ProductID"];
                int quantity = (int)e.Data["Quantity"];
                purchaseOrder.AddProduct(productID, quantity);
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("Sales.aspx.cs", "saleLookup_OnAddProduct", ex.StackTrace);
                ShowErrorMessage(purchaseOrder, "(*) Error in add product: " + ex.Message);
            }
        }
    }
}
